﻿<view:NavigationAwarePage
    xmlns:view="clr-namespace:PhoneUtils.View;assembly=PhoneUtils"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"                      
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:prismInteractivity="clr-namespace:Microsoft.Practices.Prism.Interactivity;assembly=Microsoft.Practices.Prism.Interactivity"    
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
    xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions" x:Class="WPForms.Phone.View.FormCollection" 
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="728" d:DesignWidth="480"
    DataContext="{Binding FormCollection, Source={StaticResource ViewModelLocator}}"
    x:Name="page">

    <!-- Application bar -->
    <view:NavigationAwarePage.ApplicationBar>
        <shell:ApplicationBar>
            <shell:ApplicationBarIconButton IconUri="Resources/AppBarIcons/add.png" Text="New form"/>
            <shell:ApplicationBarIconButton IconUri="Resources/AppBarIcons/save.png" Text="Backup"/>
        </shell:ApplicationBar>
    </view:NavigationAwarePage.ApplicationBar>

    <i:Interaction.Behaviors>
        <prismInteractivity:ApplicationBarButtonNavigation ButtonText="New form" NavigateTo="/WPForms.Phone;component/View/CreateForm.xaml" />
        <prismInteractivity:ApplicationBarButtonNavigation ButtonText="Backup" NavigateTo="/WPForms.Phone;component/View/SkyDriveBackup.xaml" />
    </i:Interaction.Behaviors>
    
    <Grid x:Name="LayoutRoot" Background="Transparent">
    	<i:Interaction.Behaviors>
    		<ec:DataStateBehavior Binding="{Binding Instances.Count, Mode=OneWay}" Value="0" TrueState="NoForms" FalseState="HasForms"/>
    	</i:Interaction.Behaviors>
    	<VisualStateManager.VisualStateGroups>
    		<VisualStateGroup x:Name="FormCountStates">
    			<VisualState x:Name="NoForms">
    				<Storyboard>
    					<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="emptyMessage">
    						<DiscreteObjectKeyFrame KeyTime="0">
    							<DiscreteObjectKeyFrame.Value>
    								<Visibility>Visible</Visibility>
    							</DiscreteObjectKeyFrame.Value>
    						</DiscreteObjectKeyFrame>
    					</ObjectAnimationUsingKeyFrames>
    				</Storyboard>
    			</VisualState>
    			<VisualState x:Name="HasForms">
    				<Storyboard>
    					<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="emptyMessage">
    						<DiscreteObjectKeyFrame KeyTime="0">
    							<DiscreteObjectKeyFrame.Value>
    								<Visibility>Collapsed</Visibility>
    							</DiscreteObjectKeyFrame.Value>
    						</DiscreteObjectKeyFrame>
    					</ObjectAnimationUsingKeyFrames>
    				</Storyboard>
    			</VisualState>
    		</VisualStateGroup>
    	</VisualStateManager.VisualStateGroups>
        <Grid.RowDefinitions>
        	<RowDefinition Height="Auto"/>
        	<RowDefinition Height="*"/>
        </Grid.RowDefinitions>

    	<!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="{StaticResource AppName}" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="forms" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle2Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <TextBlock x:Name="emptyMessage" VerticalAlignment="Center" TextWrapping="Wrap" Text="Click on the new form icon to create a new form..."/>
            <ListBox ItemsSource="{Binding Instances}" SelectedValue="{Binding SelectedForm, Mode=TwoWay}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="15">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="1*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <TextBlock FontWeight="Bold" Style="{StaticResource PhoneTextLargeStyle}" Text="{Binding InstanceName}"/>
                            <TextBlock Grid.Row="1" Style="{StaticResource PhoneTextNormalStyle}" Text="{Binding FormName}"/>
                            <Image Grid.Column="1" Grid.RowSpan="2" VerticalAlignment="Center" Height="64" Width="64" Source="/WPForms.Phone;component/Resources/Images/next.png"/>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>            
        </Grid>        
    </Grid>
</view:NavigationAwarePage>
